import React, { useEffect, useState } from 'react'
import { Select } from 'antd'
import { getChannels } from 'api/channel'
const { Option } = Select
export default function Channel(props) {
  const [channels, setChannels] = useState([])
  useEffect(() => {
    const getAsyncChannels = async () => {
      const res = await getChannels()
      // console.log(res)
      setChannels(res.data.channels)
    }
    getAsyncChannels()
  }, [])
  return (
    <Select
      style={{
        width: 200,
      }}
      placeholder='请选择文章频道'
      value={props.value}
      onChange={props.onChange}
    >
      {channels.map((item) => (
        <Option key={item.id} value={item.id}>
          {item.name}
        </Option>
      ))}
    </Select>
  )
}
